﻿
//队列监控对象
var evt =new clsQueueEvent();

var btnpickup={};
var btndisconnect={};
var btnhold={};
var btnmute={};
var btndail={};
var btnblindtransfer={};
var btnmarktransfer={};
var btnconsulttransfer={};
var btncanceltransfer={};
var btnmarkconference={};
var btnconsultconference={};
var btncancelconference={};
var txtPhoneNum={};

var btnbar = new clsButtonBar();

function CustomEvent(callobj, eventtype)
{
	
	var EventCallIVRInfo = new Object();
	EventCallIVRInfo["Server"] = callobj;
	var calltools=new clsCallTool(); 
	EventCallIVRInfo.CallId = calltools.GetCallAttribute(callobj.Id,"Eic_CallIdKey");//callid
	//EventCallIVRInfo.CallFromNumber = calltools.GetCallAttribute(callobj.Id,"Eic_SipNumberRemote");//进线号码
	EventCallIVRInfo.CallFromNumber = calltools.GetCallAttribute(callobj.Id,"Eic_SipNumberRemote");//进线号码   20111022,jeff要求修改成这个key
	EventCallIVRInfo.LocalIdCallNumber = calltools.GetCallAttribute(callobj.Id,"Eic_LocalId");//本地号码
	EventCallIVRInfo.CallDirection = calltools.GetCallAttribute(callobj.Id,"Eic_CallDirection");//进线方向
	EventCallIVRInfo.CustNo = calltools.GetCallAttribute(callobj.Id,"CusRealID");//订户编号
	EventCallIVRInfo.CustphoneNo = calltools.GetCallAttribute(callobj.Id,"CallNumber");//订户输入的电话
	EventCallIVRInfo.ActType = calltools.GetCallAttribute(callobj.Id,"M_Categorty");//杂志别
	
	EventCallIVRInfo.UserStatus = callobj.status;//用户状态

	logger.debug("Eic_CallIdKey --" + EventCallIVRInfo.CallId );
	logger.debug("Eic_SipNumberRemote --" + EventCallIVRInfo.SIPRemoteNumber );
	logger.debug("Eic_RemoteAddress --" + calltools.GetCallAttribute(callobj.Id,"Eic_RemoteAddress") );
	

	
	parent.SoftPhoneEvent(eventtype,EventCallIVRInfo);
}

function QueueStatsUpdated(queue)
{

  // If you want to see the individual notifications, uncomment the following
  //alert("Queue Stats Updated");
  
}


function QueueObjectAdded(queue, queueObj)
{
    // 同步电话条
	//alert("QueueObjectAdded" + queueObj.State + "||" + queueObj.Id);
    btnbar.SetCallStatus(queueObj.State,queueObj.Id);
   
    
    
    //更新电话列表
    //var text="";
   // list = evt.CallLists.GetList();
    /*for(x in list) 
    {
      
      text = text + list[ x ].Id + "-" + list[ x ].StatusName  + "-" + gettime() +"<br>" 
    }
    dataCallList.innerHTML = text;*/
    
    
    //更新当前电话
    //currid=btnbar.CurrentId();
   // datacallid.innerHTML =currid;
    
   /* var calltools=new clsCallTool();
    
    var myval ;
    myval= "Eic_CallIdKey :" + calltools.GetCallAttribute(queueObj.Id,"Eic_CallIdKey") +"<br>";
    myval= myval + "Eic_CallType :" + calltools.GetCallAttribute(queueObj.Id,"Eic_CallType")+"<br>";
    myval= myval + "cc_callid :" + calltools.GetCallAttribute(queueObj.Id,"cc_callid")+"<br>";
	myval= myval + "cc_callintime :" + calltools.GetCallAttribute(queueObj.Id,"cc_callintime")+"<br>";
	myval= myval + "cc_inlineno :" + calltools.GetCallAttribute(queueObj.Id,"cc_inlineno")+"<br>";
	myval= myval + "cc_cno :" + calltools.GetCallAttribute(queueObj.Id,"cc_cno")+"<br>";
	myval= myval + "inseq :" + calltools.GetCallAttribute(queueObj.Id,"inseq")+"<br>";
	myval= myval + "cc_custype :" + calltools.GetCallAttribute(queueObj.Id,"cc_custype")+"<br>";
	myval= myval + "Eic_RemoteAddress :" + calltools.GetCallAttribute(queueObj.Id,"Eic_RemoteAddress")+"<br>";
	myval= myval + "cc_calltype :" + calltools.GetCallAttribute(queueObj.Id,"cc_calltype");
	
    dataarea.innerHTML = myval;*/
    
    //dataarea.innerHTML = dataarea.innerHTML + "<br>" + queueObj.Id + queueObj.StateString;
  
}

function QueueObjectChanged(queue, queueObj)
{
    // 同步电话条
	//alert("QueueObjectChanged" + queueObj.State + "||" + queueObj.Id);
    btnbar.SetCallStatus(queueObj.State,queueObj.Id);
   
    
    
    //更新电话列表
	/*
    var text="";
    list = evt.CallLists.GetList();
    for(x in list) 
    {
      
      text = text + list[ x ].Id + "-" + list[ x ].StatusName + "-" + gettime() + "<br>" 
    }
    dataCallList.innerHTML = text;


	var nextcall=evt.CallLists.GetNextActiveCall();
	if(queueObj.State==106 && nextcall!=0)
	{
		var calltools=new clsCallTool();
		btnbar.SetCallStatus(calltools.GetCallState(nextcall),nextcall);
		
	}
    
    
    //更新当前电话
    currid=btnbar.CurrentId();
    datacallid.innerHTML =currid;

	
    
    dataarea.innerHTML = dataarea.innerHTML + "<br>" + queueObj.Id + queueObj.StateString  + "-" + gettime() ;*/
}

function QueueObjectRemoved(queue, objID)
{
    // 同步电话条
	//alert("QueueObjectRemoved" + queueObj.State + "||" + queueObj.Id);
    btnbar.SetCallStatus(0,objID);
  
    //更新电话列表
    /*var text="";
    list = evt.CallLists.GetList();
    for(x in list) 
    {
      
      text = text + list[ x ].Id + "-" + list[ x ].StatusName  + "-" + gettime() +"<br>" 
    }
    dataCallList.innerHTML = text;
    
    //更新当前电话
    currid=btnbar.CurrentId();
    datacallid.innerHTML =currid;

    dataarea.innerHTML = dataarea.innerHTML + "<br>" + objID   + "-" + gettime();*/
}


function LoginCIC(CallParameters)
{
	 //alert("LoginCIC");
	 Grandsys.System = "CIC";   

     var obj =new loginobj();    	    
     obj.Server = CallParameters.Server;
     obj.User =  CallParameters.AgentId;
     obj.Password = CallParameters.PassWord;
     obj.Station =  CallParameters.Station; 

     evt.SetObjectAddedFunc(QueueObjectAdded);
     evt.SetObjectChangedFunc(QueueObjectChanged);
     evt.SetObjectRemovedFunc(QueueObjectRemoved);
     evt.SetStatisticsUpdatedFunc(QueueStatsUpdated);
	 evt.SetCustomEventFunc(CustomEvent); 
     
     btnbar.SetBtnHandle(btnpickup,1);
     btnbar.SetBtnHandle(btndisconnect,2);
     btnbar.SetBtnHandle(btnhold,3);
     btnbar.SetBtnHandle(btnmute,4);
     btnbar.SetBtnHandle(btndail,5);
     btnbar.SetBtnHandle(btnblindtransfer,6);
     btnbar.SetBtnHandle(btnmarktransfer,7);
     btnbar.SetBtnHandle(btnconsulttransfer,8);
     btnbar.SetBtnHandle(btncanceltransfer,9);
     btnbar.SetBtnHandle(btnmarkconference,10);
     btnbar.SetBtnHandle(btnconsultconference,11);
     btnbar.SetBtnHandle(btncancelconference,12); 
     
     
     btnbar.SetTxtPhoneNum(txtPhoneNum); 

	
     if (Grandsys.Connect(obj,evt)!=0)
     {
		 return -999;
     }
     btnbar.SetCallStatus(0,0); 
    
   
     //Connect.disabled=true; 
	 return 0;
}


function setStatus(Status)
{
  
  var user=new clsUser();
  user.setStatus(Status);
  
  return 0;
  //setTimeout("UserWatch()", 1000)  
}

function SoftPhoneFunction(FunctionID,CallParameters)
{
	var RetVal;	
	/**
	alert("FileName---" + FileName);
	var Log = '';
	Log = Log+'FunctionID : '+FunctionID+'     ';	
	for (var key in CallParameters){
		Log = Log+'   '+key+' : '+CallParameters[key];
	}
	WriteLog('SoftPhoneOCX', 'SoftPhoneFunction', Log, LogTypeFlg.Log, FileName);
	*/
	
	//alert(FunctionID);
	switch(FunctionID){

		case FunctionType.AgentLogin: 
			RetVal =  LoginCIC(CallParameters)
			break;

        case FunctionType.AgentCloseServer:  


        	RetVal = 0;
			break;  
			
        case FunctionType.AgentLogout:
        	//签出CIC
        	Grandsys.EICConn.ForceDisconnect(CallParameters.AgentId,CallParameters.Station,true); 
        
        	RetVal = 0;
			break;    

        case FunctionType.AgentSetStatus:  
        	
        	RetVal = setStatus(CallParameters.AgentState);
			break;    

        case FunctionType.CallDial:          
			txtPhoneNum.value=CallParameters.PhoneNumber;
        	RetVal = btndail.onclick();
        	//alert("RetVal---" + RetVal);
			RetVal = 0;
			break; 
			
        case FunctionType.CallAnswer:  
        
        	RetVal = btnpickup.onclick();
			break;       

		case FunctionType.CallHangUp:  
        
        	RetVal = btndisconnect.onclick();
			break;   
			
        case FunctionType.AgentAvailable:  
			
        	RetVal = setStatus("Available");
			break;    

        case FunctionType.AgentNotReady:  

			//RetVal = setStatus("AgentNotReady");
			RetVal = setStatus(CallParameters.StatusReason);
			
			break;    

        case FunctionType.AgentAfterCallWork:  

			RetVal = setStatus("Follow Up");
			break;    

        case FunctionType.AgentOtherWork:  

			RetVal = setStatus("Do Not Disturb");
			break;    
        case FunctionType.CallHoldOn:  
        
        	RetVal = btnhold.onclick();
			break;    
			
        case FunctionType.CallHoldOff:  
        
        	RetVal = btnhold.onclick();
			break;    

        case FunctionType.CallInitiateTransfer:  

	  		txtPhoneNum.value=CallParameters.PhoneNumber;
			RetVal = btnmarktransfer.onclick();
			break;  

        case FunctionType.CallCompleteTransfer:  
        
	  		
        	RetVal = btnconsulttransfer.onclick();
			break; 
			
        case FunctionType.CallCancelTransfer:  
        
	  		
			RetVal = btncanceltransfer.onclick();
			break;    


        case FunctionType.CallInitiateConference:  
			
	  		txtPhoneNum.value=CallParameters.PhoneNumber;
        	RetVal = btnmarkconference.onclick();
			break;    

        case FunctionType.CallCancelConference:  
        
	  		
        	RetVal = btncancelconference.onclick();
			break;  
			
        case FunctionType.CallCompleteConference:  
        
	  		
        	RetVal = btnconsultconference.onclick();
			break; 

        case FunctionType.CallEndConference:  
        
        	RetVal = btndisconnect.onclick();
			break; 

		case FunctionType.CallSendDtmf:  
        
        	RetVal = 0;
			break; 

        case FunctionType.CallBlindTransfer:  
			txtPhoneNum.value=CallParameters.PhoneNumber;
        	RetVal = btnblindtransfer.onclick();
			break; 
			
        case FunctionType.CallBlindConference:  
        	RetVal = 0;
			break; 
			
        case FunctionType.CallTransferVDN:  
        	RetVal = 0;
			break; 
			

        case FunctionType.CallSupMonitor:  
        
        	RetVal = 0;
			break; 

        case FunctionType.CallSupConfere:  
        
        	RetVal = 0;
			break; 

        case FunctionType.CallSupHangup:  
        
        	RetVal = 0;
			break; 

        case FunctionType.CallSupTransfer:  
        
        	RetVal = 0;
			break; 
			
			
			
        case FunctionType.OpenRecord:  
        	        
        	RetVal = 0;
			break; 
			
        case FunctionType.RecStartRecord:  
        	        
        	RetVal = 0;
			break; 
			
        case FunctionType.RecStopRecord:  
        	        
        	RetVal = 0;
			break; 
			
        case FunctionType.RecSendRecord:  
        
            if(RecordPID==""){
        	    RetVal = 0;
        	}else{        	        
        	    RetVal = 0;
        	}
			break; 
			
        case FunctionType.GetRecStateRecord:  
        	        
        	RetVal = 0;
			break; 
			
        case FunctionType.GetPIDRecord:  
        	        
        	RetVal = 0;
			break; 
			
        case FunctionType.GetPIDSplitRecord:  
        	        
        	RetVal = 0;
			break; 
			
        case FunctionType.CloseRecord:  
        	        
        	RetVal = 0;
			break; 				

		default:
			
			var Log = "[未定义] FunctionID: " + FunctionID;
			WriteLog('SoftPhoneOCX', 'SoftPhoneFunction', Log, LogTypeFlg.Log, FileName);
			
            //alert("[Log  ： SoftPhoneFunction ：   未定义] FunctionID: " + FunctionID);
            RetVal = -999;
			break;
	}
	return RetVal;
}

